<?php


class ProfileAction extends Action {
    public function settings()
    {
        $Dao=D("user_info");
        $condition['account']=session("account");
        $info=$Dao->where($condition)->find();
        $region=$info['region'];
        list($province, $city)=split (';',$region);
        $info['province']=$province;
        $info['city']=$city;
        $this->assign("info",$info);
        $this->display();
    }

    public function studentUpdate(){
        $Dao=D("user");
        $user=session("user");
        $user['name']=$_POST[name];
        $result1=$Dao->where(array('account'=>session('account')))->save($user);
        session("user",$user);
        $Dao=D("user_info");
        $data=$_POST;
        $data=array_filter($data);
        $result2=$Dao->where(array('account'=>session('account')))->save($data);
        $this->redirect("Profile/settings",array("data"=>1));
    }

    public function create()
    {
        $this->display();
    }
    public function studentpage()
    {
        $this->display();
    }
    public function account()
    {
        $account=$_GET[account];
        $Dao=D("user");
        $list=$Dao->where(array('account'=>$account))->find();
        if($list)
            $this->ajaxReturn("true");
        else
            $this->ajaxReturn("false");
    }
    public function studentcreate()
    {
        $data=$_POST;
        $data=array_filter($data);
        $data['role']=0;
        $data['region']=$data['province'].";".$data['city'];
        $Dao1=D("user");
        $Dao2=D("user_info");
        if($Dao1->add($data)&&$Dao2->add($data)){
            session('account',$data['account']);
            session('password',$data['password']);
            echo "<script>var _parent = window.parent;_parent.location.href='".__APP__."'</script>";
        }

        else
            echo "<h1>注册失败！</h1>";
    }
}

?>